%option noyywrap
%option prefix="rep"

%{
#include <stdio.h>
#include <string.h>
#include "rep.tab.hpp"

char* rep_input_ptr;

#define YY_INPUT(buf,result,max_size) \
    { \
    int c = (*rep_input_ptr != '\0') ? *(rep_input_ptr++) : EOF; \
    result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \
    }

// flop2 operations
float fladd(float fl1, float fl2) { return fl1+fl2; }
float flsub(float fl1, float fl2) { return fl1-fl2; }
float flmul(float fl1, float fl2) { return fl1*fl2; }
float fldiv(float fl1, float fl2) { return fl1/fl2; } // be aware, no DIV/0 check!
// end flop2 operations

%}

%%
[-+]?[0-9]*\.?[0-9]+	replval.number=atof(yytext); return NUMBER;
add                     replval.flop2=&fladd; return FLOP2;
sub                     replval.flop2=&flsub; return FLOP2;
mul                     replval.flop2=&flmul; return FLOP2;
div                     replval.flop2=&fldiv; return FLOP2;
\(			return PO;
\)			return PC;
\,			return C;
\[                      replval.character=yytext[0]; return BO;
\]                      replval.character=yytext[0]; return BC;
F			replval.character=yytext[0]; return WALK;
f                       replval.character=yytext[0]; return SWIM;
\<			replval.character=yytext[0]; return TURN_LEFT;
\>			replval.character=yytext[0]; return TURN_RIGHT;
\^			replval.character=yytext[0]; return NOSE_DOWN;
v			replval.character=yytext[0]; return NOSE_UP;
\\			replval.character=yytext[0]; return ROLL_LEFT;
\/			replval.character=yytext[0]; return ROLL_RIGHT;
\|			replval.character=yytext[0]; return TURN_AROUND;
\$                      replval.character=yytext[0]; return TURN_UPRIGHT;
[a-zA-Z]                replval.character=yytext[0]; return CHAR;
\?                      return VAR;
\n                  	/* ignore end of line */;
%%

